<?php
declare (strict_types = 1);

namespace app\api\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Mission extends Model
{
	protected $pk='mission_id';
    protected $json = ['money_cfg'];
    protected $jsonAssoc = true;


    public function description(){
      return $this->hasOne("mission_description",'mission_id',"mission_id");
    }


    /**
     * 获取文件
     * @return [type] [description]
     */
    public function attach(){
    	return $this->hasOne("attach",'attach_id',"attach_id")->bind(["file_name","file_path"]);
    }


    public function descriptionShow(){
       return $this->hasOne("mission_description",'mission_id',"mission_id")->bind(['title','content','req','seo']);
    }




    public function catInfo(){
        return $this->hasMany("cat_description",'cat_id',"cat_id");
    }	 

     public function catDetail(){
        return $this->hasOne("cat",'cat_id',"cat_id")->bind(['pid']);
    }


    public function catInfoShow(){
        return $this->hasOne("cat_description",'cat_id',"cat_id")->where("language_id",getLangs(session("lang", 'zh_CN')));
    }


    public function userInfo(){
    	return $this->hasone("user",'u_id',"u_id");
    }


    public function contributes(){
         return $this->hasMany("mission_schedule",'mission_id',"mission_id");
    }


     public function getStatusTextAttr($value,$data)
    {       
        return self::getStatus($data['status']);
    }


    /**
     * 获取全部状态
     * @var [type]
     */
    public static function  getStatus($int=0){
    	$res =  [
    		1=>__('to be paid'),
    		2=>__('to be approved'),
    		3=>__('in progress'),
    		4=>__('done'),
    		5=>__('arbitration'),   
    	];
    	return $int>0 ? $res[$int]:$res;
    }


      /**
     * 获取大厅状态
     * @var [type]
     */
    public static function  getHallStatus($int=0){
        $res =  [       
            3=>__('in progress'),
            4=>__('done'),         
        ];
        return $int>0 ? $res[$int]:$res;
    }



    public function dissent(){
      return $this->hasOne("mission_dissent",'mission_id',"mission_id");
    }


}
